package ext

import (
	"hundsun.com/hsl/hschain/contract/evm/ext/common"
	pbcom "hundsun.com/hsl/hschain/protos/common"
	"math/big"
)

// Message 合约交易消息模型
// 在EVM执行器中传递此消息，由外部Tx等价构造
type Message struct {
	from       common.Address
	to         *common.Address
	nonce      int64
	value      *big.Int
	gasLimit   uint64
	gasPrice   uint32
	code       []byte
	param      []byte
	contractId *pbcom.ContractIdentifier
}

// NewMessage 新建消息结构
func NewMessage(from common.Address, to *common.Address, nonce int64, value uint64, gasLimit uint64, gasPrice uint32, code, param []byte, contractId *pbcom.ContractIdentifier) *Message {
	return &Message{
		from:       from,
		to:         to,
		nonce:      nonce,
		value:      big.NewInt(int64(value)),
		gasLimit:   gasLimit,
		gasPrice:   gasPrice,
		code:       code,
		param:      param,
		contractId: contractId,
	}
}

// From 来源
func (m *Message) From() common.Address { return m.from }

// To 目的地址
func (m *Message) To() *common.Address { return m.to }

// GasPrice Gas价格
func (m *Message) GasPrice() uint32 { return m.gasPrice }

// Value 转账金额
func (m *Message) Value() *big.Int { return m.value }

// Nonce  nonce值
func (m *Message) Nonce() int64 { return m.nonce }

// Code 部署合约代码
func (m *Message) Code() []byte { return m.code }

// GasLimit Gas限制
func (m *Message) GasLimit() uint64 { return m.gasLimit }

// GasLimit Gas限制
func (m *Message) SetGasLimit(gasLimit uint64) {
	m.gasLimit = gasLimit
}

// ContractId 合约ID
func (m *Message) ContractId() *pbcom.ContractIdentifier { return m.contractId }

// Param 合约参数
func (m *Message) Param() []byte { return m.param }
